package com.hnhcyy.goods.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hnhcyy.goods.pojo.Goods;
import com.hnhcyy.goods.pojo.GoodsQueryParam;
import com.hnhcyy.goods.pojo.SpMchk;
import com.hnhcyy.goods.pojo.SpOldMchk;
import com.hnhcyy.goods.service.EsGoodsService;
import com.hnhcyy.goods.service.GoodsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author sheyongjun
 * @Date 2019/4/13 下午 2:30
 **/
@Api(value = "/EsGoodsApi", tags = "商品搜索接口")
@RestController
@RequestMapping("esgoods")
public class EsGoodsApi {

	@Autowired
	private EsGoodsService esGoodsService;
	@Autowired
	private GoodsService goodsService;


	/**
	 * @Description: 保存所有上架的商品
	 * @Author: sheyongjun
	 * @CreateDate: 2019/4/13 下午 3:07
	 * @Version: 1.0
	 */
	@ApiOperation(value = "保存所有上架的商品", notes = "保存所有上架的商品")
	@GetMapping("/saveAllGoods")
	public String saveAllGoods() {
		List<Goods> goodsList = goodsService.getListOnSell();
		return esGoodsService.bulkSaveGoods(goodsList);
	}

	/**
	 * @Description:    保存客户加减表数据
	 * @Author:         sheyongjun
	 * @CreateDate:     2019/4/17 下午 5:41
	 * @Version:        1.0
	 */
	@ApiOperation(value = "保存客户加减表数据", notes = "保存客户加减表数据")
	@GetMapping("/saveAllSpMchk")
	public String saveAllSpMchk(List<SpMchk> spMchkList){
		return esGoodsService.bulkSaveSpMchk(spMchkList);
	}

	/**
	 * @Description:    保存老客户表数据
	 * @Author:         sheyongjun
	 * @CreateDate:     2019/4/19 下午 2:27
	 * @Version:        1.0
	 */
	@GetMapping("/saveAllSpOldMchk")
	public String saveAllOldSpMck(List<SpOldMchk> spOldMchkList){
		return esGoodsService.bulkSaveSpOldMchk(spOldMchkList);
	}

	/**
	 * @Description: 保存一个商品
	 * @Author: sheyongjun
	 * @CreateDate: 2019/4/16 下午 3:22
	 * @Version: 1.0
	 */
	@GetMapping("/saveOneGoods")
	public String saveOneGoods(Goods goods) {
		return esGoodsService.saveGoods(goods);
	}

	/**
	 * @Description:
	 * @Author:         sheyongjun
	 * @CreateDate:     2019/4/16 下午 3:26
	 * @Version:        1.0
	 */
	public boolean delete(String id, String type){
		if(esGoodsService.exists(type, id)){
			return esGoodsService.delete(type, id) == 200;
		}
		return false;
	}

	/**
	 * @Description:    根据条件搜索
	 * @Author:         sheyongjun
	 * @CreateDate:     2019/4/16 下午 3:33
	 * @Version:        1.0
	 */
	@ApiOperation(value = "搜索", notes = "条件搜索商品")
	@GetMapping("/list")
	public List<Goods> list(GoodsQueryParam queryParam) {
		return esGoodsService.list(queryParam);
	}


}
